import HTMLParser
import urllib


urlString = "http://tie.telx.com/participants/bgp_table.php"
urlText = []
pathOut = "ixp_members.txt"


class Parse15 (HTMLParser.HTMLParser):
    
    check1 = False
    check2 = False
    
    def handle_starttag (self, tag, attrs):
        if tag == "div":
            for name,value in attrs:
                if name == "id" and value == "atldiv":
                    self.check1 = True
        if tag == "td":
            for name,value in attrs:
                if name == "align" and value == "left":
                    self.check2 = True
    
    def handle_endtag (self, tag):
        if tag == "div" and self.check1 == True:
            self.check1 = False
    
    def handle_data (self, data):
        if self.check1 == True and self.check2 == True:
            if data not in urlText:
                urlText.append(data)
        self.check2 = False


lparser = Parse15()
lparser.feed(urllib.urlopen(urlString).read())
fileOut = open(pathOut, "a")
for item in urlText:
    #print item # debug
    print >> fileOut, "15 %s" % item
fileOut.close()